function cdf = bbcdf(nn,x,a,b)

if x<0
    cdf     = 0;
elseif x<nn
    cdf     = 0;
    
    for yy=0:x
        pdf = beta(a+yy,b+nn-yy) / ((nn+1)*beta(yy+1,nn-yy+1)*beta(a,b));
        cdf = cdf + pdf;
    end
    
elseif x>=nn
    cdf     = 1;
end